<!--系统消息页面body部分-->
<div class="regi_container">
<div id="regi_container" class="radius">
	<div id="regi_row_1">
		<h1 class="regi_title">查看汇率</h1>
		<form action="<?php echo site_url('Moneychange/post') ?>" method="POST" id="post_form">
		<ul class="regi_account">
        	<li class="regi_errer"></li>
        	<li style="width:100%;">
			   	<span>今日汇率</span>
                <div class="regi_input"><input type="text" style="width:50px" Id="Exchange" value="1.95"  "account_comment  radius" /></div>
	    	</li>
			<script>
			function PayType(){
				var json = <?php echo json_encode($PayTypes->result());?>;
				return json;
			}
			
			function GetFeeCalculateType(id1){
				json  = PayType();
				ret = {};
				for(i=0;i<json.length;i++){
					if(json[i]['Id']==id1){
						ret = {'Fee':json[i]['Fee'],'CalculateType':json[i]['CalculateType']};
						//$('#Fee')[0].value = json[i]['Fee'];
						//$('#CalculateType')[0].value = json[i]['CalculateType'];
					}	
				}
				return ret;
			}
			
			/*
			function select1change(o){
				json  = PayType();
				for(i=0;i<json.length;i++){
					if(json[i]['Id']==o.value){
						$('#Fee')[0].value = json[i]['Fee'];
						$('#CalculateType')[0].value = json[i]['CalculateType'];
					}	
				}
				
			}
			*/
			function inPay1change(o){
				var outPay2 = $('#outPay2')[0];
				var fee = parseFloat($('#Fee')[0].value);
				var calculateType = $('#CalculateType')[0].value;
				var exchange = parseFloat($('#Exchange')[0].value);
				var inpay = parseFloat(o.value);
				
				/*
				马币到人民币计算
				马币*汇率-手续费
				人民币到马币计算
				人民币+手续费/汇率
				*/
				//x = inpay*exchange;
				//if(calculateType=='Per')
				//	fee = 
			}
			
			function Calculate1(){
				/*
				马币到人民币计算
				马币*汇率-手续费
				人民币到马币计算
				人民币+手续费/汇率
				*/	
				var exchange = parseFloat($('#Exchange')[0].value);//汇率
				var inpay = parseFloat($('#inPay1')[0].value);//输入金额
				var payTypeId = $('#select1')[0].value;
				var fee = parseFloat(GetFeeCalculateType(payTypeId)['Fee']);//手续费
				var CalculateType = GetFeeCalculateType(payTypeId)['CalculateType'];//手续费计算方式
				var feeCtrl = $('#FeeValue1')[0];
				var countCtrl = $('#count1')[0];
				var outPay = $('#outPay1')[0];

				ret = 0;
				
				if(CalculateType=='Add'){//直接金额模式
					outPay.value = inpay * exchange;//计算汇兑金额
					feeCtrl.value = fee;//计算手续费
					v = inpay * exchange - fee;//计算总计
					countCtrl.value = Math.round(v*100)/100;//inpay * exchange - fee;//计算总计
					
				}	
				else{//百分比模式
					outPay.value = inpay * exchange;//计算汇兑金额
					feeCtrl.value = (inpay * exchange)*(fee/100);//计算手续费
					v = (inpay * exchange) - (inpay * exchange)*(fee/100);//计算总计
					countCtrl.value = Math.round(v*100)/100;//(inpay * exchange) - (inpay * exchange)*(fee/100);//计算总计
					//countCtrl.value = (inpay * exchange) + (inpay * exchange)*(fee/100);//计算总计
					//feeCtrl.value = (inpay * exchange)*(fee/100);
				}
				
			}
			
			function Calculate2(){
				/*
				马币到人民币计算
				马币*汇率-手续费
				人民币到马币计算
				人民币+手续费/汇率
				*/	
				var exchange = parseFloat($('#Exchange')[0].value);//汇率
				var inpay = parseFloat($('#inPay2')[0].value);//输入金额
				var payTypeId = $('#select2')[0].value;
				var fee = parseFloat(GetFeeCalculateType(payTypeId)['Fee']);//手续费
				var CalculateType = GetFeeCalculateType(payTypeId)['CalculateType'];//手续费计算方式
				var feeCtrl = $('#FeeValue2')[0];
				var countCtrl = $('#count2')[0];
				var outPay = $('#outPay2')[0];

				ret = 0;
				
				if(CalculateType=='Add'){//直接金额模式
					outPay.value = inpay / exchange;//计算汇兑金额
					feeCtrl.value = fee;//计算手续费
					v = inpay / exchange + fee;//计算总计
					countCtrl.value = Math.round(v*100)/100;//inpay / exchange + fee;//计算总计
					
				}	
				else{//百分比模式
					outPay.value = inpay / exchange;//计算汇兑金额
					feeCtrl.value = (inpay / exchange)*(fee/100);//计算手续费
					v = (inpay / exchange) + (inpay / exchange)*(fee/100);//计算总计
					countCtrl.value = Math.round(v*100)/100;
					//countCtrl.value = (inpay * exchange) + (inpay * exchange)*(fee/100);//计算总计
					//feeCtrl.value = (inpay * exchange)*(fee/100);
				}
			}
			</script>
        	<li> 
                <span>我要充值</span>
                <div class="regi_input">
					<input type="text" id="inPay1" style="width:50px" name="Url" value="" placeholder='金额'  "account_comment  radius" />马币
					-->
					<select id="select1">
					<?php
					foreach($PayTypes->result() as $row)
					{
						echo "<option value='$row->Id'>$row->Name</option>";
					}
					?>
					</select>
					<button type="button" class="btn btn-large btn-primary" onclick="Calculate1()">计算</button>
					<div>您可以收到<input id="outPay1" type="text" style="width:50px;" readonly  value="" placeholder=''  "account_comment  radius" />人民币，手续费<input id="FeeValue1" type="text" style="width:50px" value="" placeholder=''  "account_comment  radius" readonly />,一起人民币<input id="count1" type="text" style="width:50px" name="Url" value="" placeholder=''  "account_comment  radius" readonly />。</div>
				</div>
	    	</li>
        	<li> 
                <span>我要充值</span>
                <div class="regi_input">
					<input type="text" id="inPay2" style="width:50px" value="" placeholder='金额'  "account_comment  radius" />人民币
					----->
					<select  id="select2">
					<?php
					foreach($PayTypes->result() as $row)
					{
						echo "<option value='$row->Id'>$row->Name</option>";
					}
					?>
					</select>
					<button type="button" class="btn btn-large btn-primary" onclick="Calculate2()">计算</button>
					<div>您需要汇款<input id="outPay2" type="text" style="width:50px;" readonly  value="" placeholder=''  "account_comment  radius" />马币，手续费<input id="FeeValue2" type="text" style="width:50px" value="" placeholder=''  "account_comment  radius" readonly />,一起马币<input id="count2" type="text" style="width:50px" name="Url" value="" placeholder=''  "account_comment  radius" readonly />。</div>
				</div>
	    	</li>
        	<li><button type="submit"  class="btn btn-large btn-primary">已经汇款了，去填写汇款信息吧。</button>
			</li>
		</ul>
   		</form>
    </div>
    <div id="regi_row_2">
		<ul>
			<li><img src='http://pic1a.nipic.com/2009-01-04/200914173641218_2.jpg'/></li>
		</ul>
	</div>
	<div style="clear:both;"></div>
    </div>
</div>
<div>

</div>
<!-- Javascript for this page. -->
<script type="text/javascript">
    function TWinOpen(url,id,iWidth,iHeight)
    {
        var iTop = (screen.height-30-iHeight)/2; //获得窗口的垂直位置;
        var iLeft = (screen.width-10-iWidth)/2; //获得窗口的水平位置;
        TWin=window.showModalDialog(url,null,"dialogWidth="+iWidth+"px;dialogHeight="+iHeight+"px;dialogTop="+iTop+"px;dialogLeft="+iLeft+"px");
    }

    function iFrameHeight(frame) {   
        var ifm= $(frame);
        var subWeb = document.frames ? document.frames[frame].document : ifm.contentDocument;   
        if(ifm != null && subWeb != null) {
            ifm.height = subWeb.body.scrollHeight;
        }   
    }
</script>
